<?php
namespace app\adminmall\controller;
use app\common\controller\AdminBaseController;
use think\Db;
class PsalesController extends AdminBaseController {
	
	public function index(){
		
		
		
		
		$grab = Db::name('mall_goodstype')->field('name,id,pid')->buildSql();
		$grab1 = Db::name('mall_agent')->field('id')->buildSql();
    
	$list = Db::name('mall_order')->alias('c')->field('count(c.id) count,q.name')
	->join($grab. 'q','c.agent_id= q.pid','RIGHT')
	->join($grab1. 'n','c.agent_id=n.id','LEFT')
	->group('q.id')
	->order('count(c.id) DESC')
    ->select();



   
		 return $this->fetch('index', ['list' => $list]);
		 
	}
	public function select(){
		
	    $p=[];
    	$param = input('post.');
    	//店铺名称		
    	if($param['name']){
    	  $p['name'] = ['like', '%'.$param['name'].'%'];
    	}
    	
    		
		$grab = Db::name('mall_goodstype')->field('name,id,pid')->buildSql();
		$grab1 = Db::name('mall_agent')->field('id')->buildSql();
    
	$list = Db::name('mall_order')->alias('c')->field('count(c.id) count,q.name')
	->join($grab. 'q','c.agent_id= q.pid','RIGHT')
	->join($grab1. 'n','c.agent_id=n.id','LEFT')
		->group('q.id')
	->where($p)
	->order('count(c.id) DESC')
    ->select();
      return $this->fetch('index', ['list' => $list]);
		
		
		
	}
	
	
}
?>